package com.offcn.dao;

import com.offcn.entity.User;
import com.offcn.utils.BaseDao;

import java.util.List;

public class UserDaoImpl extends BaseDao<User> implements UserDao {
    @Override
    public User login(String username, String password) {
        return getOne("select * from user where username = ? and password = ?",User.class,username,password);
    }

    @Override
    public int add(User user) {
        return update("insert into user values(null,?,?,?,?,?,?,?,now(),?,null)",
                user.getName(),user.getPhone(),user.getAge(),user.getSex(),user.getUsername(),
                user.getPassword(),user.getStatus(),user.getRole());
    }

    @Override
    public List<User> find(String sql, Object... params) {
        return getMore(sql,User.class,params);
    }

    @Override
    public int update(User user) {
        return update("update user set name=?,phone=?,age=?,sex=?,username=?,password=?,status=?,createtime=now(),role=? where uid=?",
                user.getName(),user.getPhone(),user.getAge(),user.getSex(),user.getUsername(),user.getPassword(),user.getStatus(),
                user.getRole(),user.getUid());
    }

    @Override
    public int deleById(String uid) {
        return update("delete from user where uid =?",uid);
    }

    @Override
    public User findById(int uid) {
        return getOne("select * from user where uid =?",User.class,uid);
    }
}
